package com.shou.zhnfyxt.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shou.zhnfyxt.Dto.HotSearch;
import com.shou.zhnfyxt.entity.R;
import com.shou.zhnfyxt.entity.Region;
import com.shou.zhnfyxt.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author JCY
 * @since 2022-12-27
 */
@Controller
@RestController
@RequestMapping("/user/region")
public class RegionController {
    @Autowired
    private IRegionService regionService;

    @PostMapping("/anhui")
    public R<List<String>> anhui() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 340100, 341800);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/beijing")
    public R<List<String>> beijing() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 110100, 110100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/chongqing")
    public R<List<String>> chongqing() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 500100, 500100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/fujian")
    public R<List<String>> fujian() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 350100, 350900);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/guangdong")
    public R<List<String>> guangdong() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 440100, 445300);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/guangxi")
    public R<List<String>> guangxi() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 450100, 451400);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/guizhou")
    public R<List<String>> guizhou() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 520100, 522700);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/gansu")
    public R<List<String>> gansu() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 620100, 623000);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/hebei")
    public R<List<String>> hebei() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 130100, 131100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/henan")
    public R<List<String>> henan() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 410100, 411700);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/heilongjiang")
    public R<List<String>> heilongjiang() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 230100, 232700);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/hubei")
    public R<List<String>> hubei() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 420100, 422800);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/hunan")
    public R<List<String>> hunan() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 430100, 433100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/hainan")
    public R<List<String>> hainan() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 460100, 460300);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/jiling")
    public R<List<String>> jiling() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 220100, 222400);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/jiangsu")
    public R<List<String>> jiangsu() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 320100, 321300);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/jiangxi")
    public R<List<String>> jiangxi() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 360100, 361100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/liaoning")
    public R<List<String>> liaoning() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 210100, 211500);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/neimenggu")
    public R<List<String>> neimenggu() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 150100, 152900);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/shanxi")
    public R<List<String>> shanxi() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 140100, 141100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/shanghai")
    public R<List<String>> shanghai() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 310100, 310100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/shandong")
    public R<List<String>> shandong() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 370100, 371700);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/sichuan")
    public R<List<String>> sichuan() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 510100, 513400);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/shanxii")
    public R<List<String>> shanxii() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 610100, 611100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping("/tianjing")
    public R<List<String>> tianjing() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 120100, 120100);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }
    @PostMapping("/zhejiang")
    public R<List<String>> zhejiang() {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id", 330100, 331200);
        queryWrapper.eq("level", 2);
        List<Region> list = regionService.list(queryWrapper);
        List<String> cityList = list.stream().map(Region::getSname).collect(Collectors.toList());
        return R.success(cityList);
    }

    @PostMapping(value = "/search" )
    public R<List<HotSearch>> search(@RequestBody String houseSearch) {
        return regionService.search(houseSearch);
    }
}

